﻿@page "/contentcenter"

@attribute [Authorize]

@inject IDataCacheService _dataCacheService
@inject NavigationManager NavigationManager
@implements IDisposable

<CnGalWebSite.Shared.MasaComponent.Shared.Cards.TitleTip Title="@("内容中心"+Tab switch {"monitor"=>" - 监视列表","review"=> " - 审阅记录列表","editrecord" =>" - 审核",_=>""})" />
<MDCard Class="mb-4">
    <MTabs Value="TabIndex" ValueChanged="IndexChanged" IconsAndText Grow CenterActive>
         <MTab Value="1">
             概览<MIcon>mdi-home</MIcon>
         </MTab>
         <MTab Value="2">
             关注<MIcon>mdi-monitor</MIcon>
         </MTab>
         <MTab Value="3">
             审阅记录<MIcon>mdi-read</MIcon>
         </MTab>
         <MTab Value="4">
             审核<MIcon>mdi-pencil</MIcon>
         </MTab>
        <MTab Value="5">
            编辑记录<MIcon>mdi-script-text-outline</MIcon>
        </MTab>
    </MTabs>
    </MDCard>

<MTabsItems @bind-Value="TabIndex">
    <MTabItem Value="1">

        <CnGalWebSite.Shared.MasaComponent.PC.EditRecords.HomeCard />
    </MTabItem>
    <MTabItem Value="2">
            <CnGalWebSite.Shared.MasaComponent.PC.EditRecords.UserCenter.Monitors.ListCard />
    </MTabItem>
    <MTabItem Value="3">
        <CnGalWebSite.Shared.MasaComponent.PC.EditRecords.UserCenter.ReviewEditRecords.ListCard/>
    </MTabItem>
    <MTabItem Value="4">
       <CnGalWebSite.Shared.MasaComponent.PC.EditRecords.UserCenter.Examines.ListCard/>
    </MTabItem>
    <MTabItem Value="5">
        <CnGalWebSite.Shared.MasaComponent.PC.Users.ExaminesCard Id="@_dataCacheService.UserInfor.Id" />
    </MTabItem>
</MTabsItems>



@code {
    [SupplyParameterFromQuery]
    [Parameter]
    public string Tab { get; set; }

    public StringNumber TabIndex { get; set; } = 1;

    protected override void OnAfterRender(bool firstRender)
    {
        if (firstRender)
        {
            NavigationManager.LocationChanged -= LocationChanged;
            NavigationManager.LocationChanged += LocationChanged;
        }
    }

    protected override void OnInitialized()
    {

        LocationChanged(null, null);

    }

    public void LocationChanged(object sender, LocationChangedEventArgs args)
    {
        TabIndex = Tab switch
        {
            "monitor" => 2,
            "review" => 3,
            "editrecord" => 4,
            "examines" => 5,
            _ => 1
        };
        StateHasChanged();
    }

    public void IndexChanged(StringNumber value)
    {
        TabIndex = value;

        NavigationManager.NavigateTo(TabIndex.ToInt32() switch
        {
            2 => "/contentcenter?Tab=monitor",
            3 => "/contentcenter?Tab=review",
            4 => "/contentcenter?Tab=editrecord",
            5 => "/contentcenter?Tab=examines",
            _ => "/contentcenter"
        });

        

    }


    #region 释放实例

    public void Dispose()
    {

        NavigationManager.LocationChanged -= LocationChanged;

        GC.SuppressFinalize(this);
    }
    #endregion
}

